<?xml version="1.0" encoding="utf-8"?>
<!--
   This file is a part of dcstore project,
   licensed under GPLv2
  
   Dominik Cebula
   dominikcebula@gmail.com
-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:t="http://myfaces.apache.org/tomahawk"
      xmlns:c="http://java.sun.com/jsp/jstl/core"
      xmlns:f="http://java.sun.com/jsf/core">

    <body>

        <ui:composition template="./admin-template.xhtml">

            <ui:define name="main">
                <div id="HeaderInfo">#{imagesWeb.headerInfo}</div>

                <h:form  id="uploadForm" enctype="multipart/form-data">
                    <t:inputFileUpload value="#{imagesWeb.file}" />
                    <h:commandButton value="Upload image"
                                     action="#{imagesWeb.add()}" />

                    <h:messages for="uploadForm" />
                </h:form>

                <c:choose>
                    <c:when test="#{imagesWeb.images.size()>0}">
                        <h:dataTable id="tbl_images"
                                     value="#{imagesWeb.images}"
                                     var="img">
                            <h:column headerClass="col1">
                                <f:facet name="header">
                                    id
                                </f:facet>
                                #{img.id}
                            </h:column>
                            <h:column headerClass="col2">
                                <f:facet name="header">
                                    image
                                </f:facet>
                                <h:graphicImage value="#{imagesWeb.getImgURL(img.product.id, img.id, 'mini')}"
                                                width="100" />
                            </h:column>
                            <h:column headerClass="col3">
                                <f:facet name="header">
                                    cover
                                </f:facet>                                
                                <h:form>
                                    <h:commandLink value="#{imagesWeb.isCover(img.id)==true ? 'Yes' : 'No'}"
                                                   action="#{imagesWeb.toggleCover()}">
                                        <f:param name="id"
                                                 value="#{img.id}" />
                                    </h:commandLink>
                                </h:form>                                
                            </h:column>
                            <h:column headerClass="col4">
                                <f:facet name="header">
                                    position
                                </f:facet>
                                #{img.position}
                            </h:column>
                            <h:column headerClass="col5">
                                <f:facet name="header">
                                    actions
                                </f:facet>
                                <h:form>
                                    <h:commandLink value="Delete"
                                                   onclick="return confirm('Are you sure you want to delete this image?')"
                                                   action="#{imagesWeb.del()}">
                                        <f:param name="id" value="#{img.id}" />
                                    </h:commandLink>
                                </h:form>
                            </h:column>
                        </h:dataTable>
                    </c:when>
                    <c:otherwise>
                        No images found for this product, use upload form above to add pictures.
                    </c:otherwise>
                </c:choose>

                <p />
                <h:link value="Go back to product list"
                        outcome="admin-products.xhtml" />
            </ui:define>

        </ui:composition>

    </body>
</html>
